package com.example.filter.test;/*
   
/**
* @program: demo
*
* @description: 过滤器
*
* @author: kk
*
* @create: 2020-02-10 10:25
**/
//springboot 整合filter如下：
//1.实现javax.servlet.Filter。2.在实现类上添加@WebFilter注解。3.在项目入口类上添加@ServletComponentScan
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
//urlPatterns表示需要过滤的url
//此处实现登陆鉴权--基于过滤器实现
@WebFilter(filterName = "myFilter",urlPatterns = "/**")
public class MyFilter implements Filter {


    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    System.out.println("过滤器初始化。。。");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("开始执行过滤操作。。。");
        //
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {
        System.out.println("过滤器销毁。。。");
    }
}
